package com.next.aappublicapp.adapters;

import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.next.aap.client.AssemblyConstituencyWithManifesto;
import com.next.aappublicapp.R;

public class StateConstituencyManifestoListAdapter extends ArrayAdapter<AssemblyConstituencyWithManifesto> {
 
	public StateConstituencyManifestoListAdapter(Context context, List<AssemblyConstituencyWithManifesto> values) {
		super(context, R.layout.activity_state_constituency_candidate, values.toArray(new AssemblyConstituencyWithManifesto[values.size()]));
	}
 
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
 
		View rowView = inflater.inflate(R.layout.assembly_constituency_manifesto_row, parent, false);
		LinearLayout acRow = (LinearLayout)rowView.findViewById(R.id.ac_row);
		TextView textView = (TextView) rowView.findViewById(R.id.ac_name);
		TextView manifestoAvailableTextView = (TextView) rowView.findViewById(R.id.ac_manifesto_available);
		textView.setText(getItem(position).getName());
		if((getItem(position).isAvailable())){
			manifestoAvailableTextView.setText("Manifesto Available");	
		}else{
			manifestoAvailableTextView.setText("Manifesto Not Available");
		}
		
		if(position % 2 == 0){
			acRow.setBackgroundColor(Color.WHITE);
		}else{
			acRow.setBackgroundColor(Color.LTGRAY);
		}
		return rowView;
	}
}
